﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace domain
{
    public abstract class KbSqlConnection
    {
        private SqlConnectionStringBuilder SqlConnectionStringBuilder;
        private SqlConnection SqlConnection;

        protected SqlDataAdapter SqlDataAdapter { get; private set; }
        protected DataSet DataSet { get; private set; }

        protected void Initialize(String StoredProcedure)
        {
            this.SqlConnectionStringBuilder = new SqlConnectionStringBuilder();
            this.SqlConnectionStringBuilder.DataSource = System.Environment.MachineName;
            this.SqlConnectionStringBuilder.InitialCatalog = DomainResource.InitialCatalog; ;
            this.SqlConnectionStringBuilder.IntegratedSecurity = true;
            this.SqlConnection = new SqlConnection(SqlConnectionStringBuilder.ConnectionString);
            this.SqlConnection.Open();
            this.SqlDataAdapter = new SqlDataAdapter(StoredProcedure, this.SqlConnection);
            this.SqlDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
            this.DataSet = new DataSet();
        }

        protected void Dispose()
        {
            this.SqlDataAdapter.Dispose();
            this.SqlConnection.Close();
            this.SqlConnection.Dispose();
            this.DataSet.Dispose();
        }
    }
}
